
<include file="mobile/Public/header" />
<link rel="stylesheet" href="__CSS__/coupon.css">
<style>
    .btn-footer{  margin-top: 2rem;  }
    .coupon-cover{  margin: 0 auto;  display: block;  }
</style>
<header class="color-main vertical-box">
    <span class="header-title">领取优惠券</span>
    <div class="header-left vertical-box">
        <img class="img-btn" src="__IMG__/back.png" onclick="history.back()">
    </div>
    <div class="header-right vertical-box">
        <img class="img-btn" src="__IMG__/home.png" onclick="window.location.href='{:U('shop/index/index')}'">
    </div>
</header>
<article class="coupon-container">
    <php>
		if(!empty($coupon['list'])){
        foreach($coupon['list'] as $c){
            </php>
            <section class="coupon-section clearfix">
                <div class="coupon-left border-box">
                    <p class="coupon-desc small-text">
                        <!--<img class="coupon-logo" src="__IMG__/coupon-logo.png">-->
                        <php>
                        if(!empty($c['rule']['min_price'])){
                            echo '付款金额满'.($c['rule']['min_price']/100).'可用';
                        }
                        else{
                            echo '无条件使用';
                        }
                        </php>
                    </p>
                    <p class="coupon-price">
	                    ￥<span class="coupon-num"><php> echo floor($c['rule']['discount']/100) </php></span><span class="coupon-num-top">.<php> printf("%'02d", $c['rule']['discount']%100); </php></span>
                    </p>
                    <p class="coupon-bottom-tips small-text">
                    <span>
                        有效期：
                        <php>
                        if(!empty($c['duration'])){
                            echo date('Y.m.d',$c['create_time']) .'-'. date('Y.m.d',($c['create_time']+$c['duration']));
                        }
                        else{
                            echo '永久';
                        }
                        </php>
                    </span>
                    </p>
                </div>
                <div class="coupon-right border-box">
                    <p class="right-text">现金券</p>
                </div>
            </section>
            <footer class="btn-footer footer-one-btn clearfix border-box" style="border-bottom: thin solid #d3d3d3;padding-bottom: 2rem">
                <button class="get-coupon-btn color-primary" data-id="<php> echo $c['id'] </php>">点击领取</button>
            </footer>
            <php>
        }
        </php>
    <php>
	    }
	    else
	    {
	        echo '<p class="list-bottom-tips">没有优惠券</p>';
	    }
    </php>
</article>

<include file="mobile/Public/footer" />


<script>
    //'jquery' or 'zepto' 脚本入口,按情况选择加载
    seajs.use(['zepto'], function () {
        $(document).ready(function () {
            $('.get-coupon-btn').click(function () {

                var id = $(this).data('id');
                $.post('{:U('shop/index/add_user_coupon')}',{coupon_id:id}, function (ret) {
                    ret = JSON.parse(ret);
                    if(ret.status==1){
                        alert('领取成功');
                        window.location.href='{:U('shop/index/user_coupon')}'
                    }
                    else{
                        alert('领取失败，'+ret.info);
                    }
                })
            })
        })
    });
</script>
</body>
</html>